using System;
using System.Reflection;
using System.Drawing;
using System.Drawing.Imaging;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Windows.Forms;


namespace stsdev {

  class SimpleFeatureSolutionProvider : ISolutionProvider {

    public string Title {
      get { return "Simple Feature Solution (C# assembly)"; }
    }

    private FeatureScopeEnum _FeatureScope;
    public FeatureScopeEnum FeatureScope {
      get { return _FeatureScope; }
      set { _FeatureScope = value; }
    }

    private bool _IncludeFeatureReceiver;
    public bool IncludeFeatureReceiver {
      get { return _IncludeFeatureReceiver; }
      set { _IncludeFeatureReceiver = value; }
    }

    public void InitializeSolution() {
       
      // interface with user to determine feature options
      SelectFeatureOptions dlg = new SelectFeatureOptions();
      DialogResult result = dlg.ShowDialog();

      if (result == DialogResult.OK) {
        FeatureScope = dlg.FeatureScope;
        IncludeFeatureReceiver = dlg.IncludeFeatureReceiver;
      }
      else {
        FeatureScope = FeatureScopeEnum.Web;
        IncludeFeatureReceiver = true;
      }

      SolutionBuilder.AssemblyDeployment = IncludeFeatureReceiver;
      SolutionBuilder.SafeControlSettings = false;
      SolutionBuilder.DeploymentTarget = AssemblyDeploymentTarget.GlobalAssemblyCache;
      SolutionBuilder.CasPermissions = false;
    }

    public void AddSolutionItems() {

      ImageFileBuilder.Create(Properties.Resources.AfricanPith32, "AfricanPith32.gif");
      FeatureBuilder.CreateElementManifest("elements.xml", ElementsWriter);
      FeatureBuilder.Create(SolutionBuilder.SolutionName, 
                            FeatureScope,
                            IncludeFeatureReceiver);       
      
    }

    void ElementsWriter(XmlWriter writer) {
      writer.WriteComment("TODO: Add Your CAML Elements Here");
    }

  }
}
